package com.ah.shanxi_demo.common.excel;

import com.ah.shanxi_demo.sync.model.*;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import java.util.ArrayList;
import java.util.List;

import static com.ah.shanxi_demo.service.impl.FileService.getCellFormatValue;


/**
 * @author zt 2020/8/20
 */
public class ExcelType {

    /**
     * 导入边界防护类
     * @param sheet
     * @return
     */
    public static List<ALM011> convert_policy_type1(Sheet sheet) {

        List<ALM011> list = new ArrayList<ALM011>();

        //循环行  sheet.getPhysicalNumberOfRows()是获取表格的总行数
        for (int i = 1; i < sheet.getPhysicalNumberOfRows(); i++) {
            Row row = sheet.getRow(i); // 取出第i行  getRow(index) 获取第(index+1)行
            if (row != null) {
                ALM011 model = new ALM011();
                if (StringUtils.isNotBlank(getCellFormatValue(row.getCell(0)))) {

                    model.setTime(getCellFormatValue(row.getCell(0)));
                    model.setRuleid(Integer.valueOf(getCellFormatValue(row.getCell(1))));
                    model.setAction(getCellFormatValue(row.getCell(2)));
                    model.setProtocol(getCellFormatValue(row.getCell(3)));
                    model.setSip(getCellFormatValue(row.getCell(4)));
                    model.setSport(getCellFormatValue(row.getCell(5)));
                    model.setDip(getCellFormatValue(row.getCell(6)));
                    model.setDport(getCellFormatValue(row.getCell(7)));
                    model.setNat_sip(getCellFormatValue(row.getCell(8)));
                    model.setNat_sport(getCellFormatValue(row.getCell(9)));
                    model.setNat_dip(getCellFormatValue(row.getCell(10)));
                    model.setNat_dport(getCellFormatValue(row.getCell(11)));
                    model.setSmac(getCellFormatValue(row.getCell(12)));
                    model.setDmac(getCellFormatValue(row.getCell(13)));
                    model.setUser(getCellFormatValue(row.getCell(14)));

                    list.add(model);
//                        model.setApply(String.valueOf(Math.round(Float.parseFloat(getCellFormatValue(row.getCell(1))))));
//                        model.setPass(String.valueOf(Math.round(Float.parseFloat(getCellFormatValue(row.getCell(2))))));
//                        model.setPass_rate(getFloatStr1(getCellFormatValue(row.getCell(3))));
//                        model.setLoan(getCellFormatValue(row.getCell(4)));
//                        model.setLoan_rate(getFloatStr1(getCellFormatValue(row.getCell(5))));

                }
            }
        }
        return list;
    }


    /**
     * 入侵防范类
     * @param sheet
     * @return
     */
    public static List<ALM012> convert_policy_type2(Sheet sheet) {

        List<ALM012> list = new ArrayList<>();

        //循环行  sheet.getPhysicalNumberOfRows()是获取表格的总行数
        for (int i = 1; i < sheet.getPhysicalNumberOfRows(); i++) {
            Row row = sheet.getRow(i); // 取出第i行  getRow(index) 获取第(index+1)行
            if (row != null) {
                ALM012 model = new ALM012();
                if (StringUtils.isNotBlank(getCellFormatValue(row.getCell(0)))) {

                    model.setAction(getCellFormatValue(row.getCell(0)));
                    model.setSip(getCellFormatValue(row.getCell(1)));
                    model.setSport(getCellFormatValue(row.getCell(2)));
                    model.setDip(getCellFormatValue(row.getCell(3)));
                    model.setDport(getCellFormatValue(row.getCell(4)));
                    model.setSmac(getCellFormatValue(row.getCell(5)));
                    model.setDmac(getCellFormatValue(row.getCell(6)));
                    model.setEvent_name(getCellFormatValue(row.getCell(7)));
                    model.setVid(Integer.valueOf(getCellFormatValue(row.getCell(8))));
                    model.setLasttimes(Integer.valueOf(getCellFormatValue(row.getCell(9))));
                    model.setDate(getCellFormatValue(row.getCell(10)));
                    model.setRawlen(Integer.valueOf(getCellFormatValue(row.getCell(11))));
                    model.setRawinfo(getCellFormatValue(row.getCell(12)));
                    model.setAr(Integer.valueOf(getCellFormatValue(row.getCell(13))));
                    model.setDs(getCellFormatValue(row.getCell(14)));
                    model.setCard(getCellFormatValue(row.getCell(15)));
                    model.setDs(getCellFormatValue(row.getCell(16)));

                    list.add(model);
                }
            }
        }
        return list;
    }

    /**
     * 病毒防护类（硬件）
     * @param sheet
     * @return
     */
    public static List<ALM013> convert_policy_type3(Sheet sheet) {

        List<ALM013> list = new ArrayList<>();

        //循环行  sheet.getPhysicalNumberOfRows()是获取表格的总行数
        for (int i = 1; i < sheet.getPhysicalNumberOfRows(); i++) {
            Row row = sheet.getRow(i); // 取出第i行  getRow(index) 获取第(index+1)行
            if (row != null) {
                ALM013 model = new ALM013();
                if (StringUtils.isNotBlank(getCellFormatValue(row.getCell(0)))) {

                    model.setAction(getCellFormatValue(row.getCell(0)));
                    model.setSip(getCellFormatValue(row.getCell(1)));
                    model.setSport(getCellFormatValue(row.getCell(2)));
                    model.setDip(getCellFormatValue(row.getCell(3)));
                    model.setDport(getCellFormatValue(row.getCell(4)));
                    model.setSmac(getCellFormatValue(row.getCell(5)));
                    model.setDmac(getCellFormatValue(row.getCell(6)));
                    model.setEvent_name(getCellFormatValue(row.getCell(7)));
                    model.setVid(Integer.valueOf(getCellFormatValue(row.getCell(8))));
                    model.setLasttimes(Integer.valueOf(getCellFormatValue(row.getCell(9))));
                    model.setDate(getCellFormatValue(row.getCell(10)));
                    model.setRawlen(Integer.valueOf(getCellFormatValue(row.getCell(11))));
                    model.setRawinfo(getCellFormatValue(row.getCell(12)));
                    model.setAr(Integer.valueOf(getCellFormatValue(row.getCell(13))));
                    model.setDs(getCellFormatValue(row.getCell(14)));
                    model.setCard(getCellFormatValue(row.getCell(15)));
                    model.setDs(getCellFormatValue(row.getCell(16)));

                    list.add(model);
//                        model.setApply(String.valueOf(Math.round(Float.parseFloat(getCellFormatValue(row.getCell(1))))));
//                        model.setPass(String.valueOf(Math.round(Float.parseFloat(getCellFormatValue(row.getCell(2))))));
//                        model.setPass_rate(getFloatStr1(getCellFormatValue(row.getCell(3))));
//                        model.setLoan(getCellFormatValue(row.getCell(4)));
//                        model.setLoan_rate(getFloatStr1(getCellFormatValue(row.getCell(5))));

                }
            }
        }
        return list;
    }

    /**
     * 安全准入类
     * @param sheet
     * @return
     */
    public static List<ALM014> convert_policy_type4(Sheet sheet) {

        List<ALM014> list = new ArrayList<>();

        //循环行  sheet.getPhysicalNumberOfRows()是获取表格的总行数
        for (int i = 1; i < sheet.getPhysicalNumberOfRows(); i++) {
            Row row = sheet.getRow(i); // 取出第i行  getRow(index) 获取第(index+1)行
            if (row != null) {
                ALM014 model = new ALM014();
                if (StringUtils.isNotBlank(getCellFormatValue(row.getCell(0)))) {

                    model.setSrcip(getCellFormatValue(row.getCell(0)));
                    model.setSrcport(getCellFormatValue(row.getCell(1)));
                    model.setSmac(getCellFormatValue(row.getCell(2)));
                    model.setDstip(getCellFormatValue(row.getCell(3)));
                    model.setDstport(getCellFormatValue(row.getCell(4)));
                    model.setDmac(getCellFormatValue(row.getCell(5)));
                    model.setByteall(Long.valueOf(getCellFormatValue(row.getCell(6))));
                    model.setPkgall(Long.valueOf(getCellFormatValue(row.getCell(7))));
                    model.setUpdatetime(getCellFormatValue(row.getCell(8)));
                    model.setSrc_status(Integer.valueOf(getCellFormatValue(row.getCell(9))));
                    model.setDst_status(Integer.valueOf(getCellFormatValue(row.getCell(10))));
                    model.setPolicyname(getCellFormatValue(row.getCell(11)));
                    model.setByteup(Long.valueOf(getCellFormatValue(row.getCell(12))));
                    model.setBytedn(Long.valueOf(getCellFormatValue(row.getCell(13))));
                    model.setPkgup(Long.valueOf(getCellFormatValue(row.getCell(14))));

                    model.setPkgdn(Long.valueOf(getCellFormatValue(row.getCell(15))));
                    model.setBehavior_type(Integer.valueOf(getCellFormatValue(row.getCell(16))));
                    model.setProtocol(getCellFormatValue(row.getCell(17)));

                    list.add(model);
//                        model.setApply(String.valueOf(Math.round(Float.parseFloat(getCellFormatValue(row.getCell(1))))));
//                        model.setPass(String.valueOf(Math.round(Float.parseFloat(getCellFormatValue(row.getCell(2))))));
//                        model.setPass_rate(getFloatStr1(getCellFormatValue(row.getCell(3))));
//                        model.setLoan(getCellFormatValue(row.getCell(4)));
//                        model.setLoan_rate(getFloatStr1(getCellFormatValue(row.getCell(5))));

                }
            }
        }
        return list;
    }

    /**
     * 防病毒软件类
     * @param sheet
     * @return
     */
    public static List<ALM015> convert_policy_type5(Sheet sheet) {

        List<ALM015> list = new ArrayList<>();

        //循环行  sheet.getPhysicalNumberOfRows()是获取表格的总行数
        for (int i = 1; i < sheet.getPhysicalNumberOfRows(); i++) {
            Row row = sheet.getRow(i); // 取出第i行  getRow(index) 获取第(index+1)行
            if (row != null) {
                ALM015 model = new ALM015();
                if (StringUtils.isNotBlank(getCellFormatValue(row.getCell(0)))) {

                    model.setHost_ip(getCellFormatValue(row.getCell(0)));
                    model.setHost_mac(getCellFormatValue(row.getCell(1)));
                    model.setHost_name(getCellFormatValue(row.getCell(2)));
                    model.setLatest_scan_time(getCellFormatValue(row.getCell(3)));
                    model.setVirus_version(getCellFormatValue(row.getCell(4)));
                    model.setSoftware_version(getCellFormatValue(row.getCell(5)));
                    model.setVirus_name(getCellFormatValue(row.getCell(6)));
                    model.setInfected_time(getCellFormatValue(row.getCell(7)));
                    model.setScan_type(Integer.valueOf(getCellFormatValue(row.getCell(8))));
                    model.setAction(Integer.valueOf(getCellFormatValue(row.getCell(9))));
                    model.setProcess_result(Integer.valueOf(getCellFormatValue(row.getCell(10))));

                    list.add(model);
//                        model.setApply(String.valueOf(Math.round(Float.parseFloat(getCellFormatValue(row.getCell(1))))));
//                        model.setPass(String.valueOf(Math.round(Float.parseFloat(getCellFormatValue(row.getCell(2))))));
//                        model.setPass_rate(getFloatStr1(getCellFormatValue(row.getCell(3))));
//                        model.setLoan(getCellFormatValue(row.getCell(4)));
//                        model.setLoan_rate(getFloatStr1(getCellFormatValue(row.getCell(5))));

                }
            }
        }
        return list;
    }
}
